<template>
	<view>
		<u-notify ref="uNotify"></u-notify>
		<view style="display: flex; justify-content:space-between">
			<u-button type="primary" text="添加维护记录" @click="add" ></u-button>
		</view>
		<!-- <u-search v-model="keyword" :show-action="false" @change="searchlist" placeholder="请输入关键字"></u-search> -->
		<u-list @scrolltolower="scrolltolower" v-if="orderList != false || status == 'loading'">
			<u-list-item v-for="(item, index) in orderList" :key="index">
				<u-cell :title="(index+1)+'、'+ item.Address" @click="openpage" :name="item.Id">
					<view slot="label" style="font-size: 12px;color: #909193;line-height: 18px;">
						<span>{{'工单编号:' + (item.No || '') + ' 网络类型:' + (item.NetType || '') + ' 润象接单人:'}}</span>
						<span>{{(item.ReceiveOrderManName || '')}}</span>
					</view>
					<!-- <view slot="right-icon">
						<u-button type="primary" @click.native.stop="toApply(item.Id,item.Name)">申请</u-button>
					</view> -->
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" v-if="loading" />
		</u-list>
		<u-empty mode="data" icon="https://project.gxrunxiang.com/cdn/list.png" v-else>
		</u-empty>
	</view>
</template>

<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		getorderlist,
		GetListByParent
	} from '@/common/api.js'
	export default {
		data() {
			return {
				orderList: [],
				keyword: "",
				pageIndex: 1, //当前页数
				pageSize: 20, //页数大小
				totalPage: "", //总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				loading: true,
				user: {},
				keyword: "",
				affiliationKey: "",
				userfilter: {},
				carName: "",
				carId: "",
				theTime: new Date().getTime(),
			}
		},
		onLoad() {
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
		},
		onShow() {
			this.orderList = []
			this.pageIndex = 1
			this.getlist()
		},
		methods: {
			openpage(e) {
				uni.navigateTo({
					url: "orderdetail?Id=" + e.name
				})
			},
			async getlist() {
				this.status = 'loading'
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters: [],
				}
				if(this.user.Roles == '项目经理角色' || this.user.Roles == '施工负责人角色'){
					para.Parameters.push({
						FieldName: "CreatorId",
						ConditionalType: "Like",
						FieldValue: this.user.Id
					})
				}
				para.OrderBys = ['CreateTime desc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex
				// if (querytype == "日志") {


				// }
				await getorderlist(para).then(res => {
					let data = res.data
					this.orderList.push(...data)
					this.total = res.count
					this.totalPage = Math.ceil(this.total / this.pageSize)
				})
				if (this.orderList.length < this.pageSize) {
					this.loading = false; //如果数据列表小于当前页数，就让加载标签消失
					this.status = 'nomore';
				} else {
					this.status = 'loadmore';
				}

			},
			scrolltolower() {
				// 如果当前页数大于等于总页数，状态修改为没有更多了，不再继续往下执行代码
				if (this.pageIndex >= this.totalPage) {
					this.status = 'nomore';
					return;
				};
				this.status = 'loading'; //状态改为加载中
				this.pageIndex = ++this.pageIndex; //页面新增一页
				this.getlist(); //修改页数后，重新获取数据
			},
			async searchlist() {
				this.orderList = [] //初始化
				this.pageIndex = 1 //初始化当前页数为1
				this.loading = true
				await this.getlist()
			},
			add() {
				uni.navigateTo({
					url: "addorder"
				})
			},
		},
	}
</script>

<style>

</style>